package com.tchintech.pay.view.activity;

import android.view.KeyEvent;

import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.tchintech.pay.delegate.ShopDelegate;
import com.tchintech.pay.frame.presenter.ActivityPresenter;

/**
 * Created by Administrator on 2017/7/15 0015.
 */

public class ShopActiviy extends ActivityPresenter<ShopDelegate> implements View.OnClickListener {
    private WebView shop_web;
    private String url = "http://wx.zuoshi.me/app/index.php?i=6&c=entry&m=ewei_shopv2&do=mobile&r=diypage&id=6";

    @Override
    protected void initView() {
        super.initView();
        shop_web = viewDelegate.getshop_web();
        WebSettings webSettings = shop_web.getSettings();
        //使用js展示js网页特效
        webSettings.setJavaScriptEnabled(true);
        shop_web.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        shop_web.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                if (newProgress == 100) {
                    hideProgressDialog();
                } else {
                    if (pd == null) {
                        showProgressDialog("", "加载中，请稍后...");
                    }
                }
            }
        });
        shop_web.loadUrl(url);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && shop_web.canGoBack()) {
            // 返回键退回
            shop_web.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onClick(View v) {

    }

    @Override
    protected Class<ShopDelegate> getDelegateClass() {
        return ShopDelegate.class;
    }
}
